export const checkAccountReg = (value) => {
    return /^[\u4E00-\u9FA5a-zA-Z0-9_-]{3,12}$/.test(value)
}

export const checkPwdReg = (value) => {
    return /^[a-zA-Z0-9_-]{6,12}$/.test(value)
}

// 处理补零函数
export const padZero = (n) => {
    return n < 10 ?  '0' + n : n
}

// 处理时间格式化的函数
export const normalizeDate = (time, s='-') => {
    let date = new Date(time);

    let y = date.getFullYear();
    let m = date.getMonth() + 1;
    let d = date.getDate();


    return [y, m, d].map(v => padZero(v)).join(s)
}

// 处理时间时分秒格式化的函数
export const normalizeFullDate = (atime, sp='-', hmins=':') => {
  let date = new Date(atime);

  let y = date.getFullYear();
  let m = date.getMonth() + 1;
  let d = date.getDate();
  
  let h = date.getHours();
  let min = date.getMinutes();
  let s = date.getSeconds();


  return [y, m, d].map(v => padZero(v)).join(sp) + ' ' +  [h, min, s].map(i => padZero(i)).join(hmins)
}

// 验证表单账号的validate函数
export const accountvalidator = (rule, value, callback) => {
   // 需要验证的是 不能为空, 正则表达式匹配还有长度
   if (!value) {
    callback(new Error('请输入账号')) 
  } else if(!checkAccountReg(value)) {
    callback(new Error('3 ~ 12 位,数字/字母/中文'))
  } else {
    callback()
  }
}

